package com.efuture.io;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @ClassNAME InputStreamReadeTest
 * @Description InputStreamReader 将字节流转换成字符流
 * @Author zhaoshanshan
 * @Date 2021/9/8 8:45 下午
 * @Version 1.0
 */
public class InputStreamReaderTest {

    public static void main(String[] args) {
        InputStreamReader isr = null;
        try{
            isr = new InputStreamReader(new FileInputStream("javasestudy/src/com.efuture.io/TestFileOne.txt"));
            StringBuffer sb = new StringBuffer();
            int readCount = -1;
            char [] chars = new char[4];
            while ((readCount = isr.read(chars))!=-1){
                sb = sb.append(new String(chars,0,readCount));
            }
            System.out.println(sb);
        }catch (Exception e){
            e.getStackTrace();
        }finally {
            if(null!=isr){
                try {
                    isr.close();
                    isr = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}